//
//  BSBFriendTitleView.m
//  Baisebudejie
//
//  Created by apple on 16/3/14.
//  Copyright © 2016年 youminuo. All rights reserved.
//

#import "BSBFriendTitleView.h"

@interface BSBFriendTitleView ()
@property (weak, nonatomic) UIButton *oneBtn;
@property (weak, nonatomic) UIButton *scendBtn;
@property (weak, nonatomic) UIView *lineView;
@property (weak, nonatomic) UIButton *seleBtn;
@end

@implementation BSBFriendTitleView



- (instancetype)initWithFrame:(CGRect)frame
{
    if (self = [super initWithFrame:frame])
    {
//        添加第一个按钮
        UIButton *oneBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        [oneBtn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
        [oneBtn setTitleColor:[UIColor redColor] forState:UIControlStateSelected];
        
        oneBtn.tag = 10;
        [oneBtn addTarget:self action:@selector(btnDidClick:) forControlEvents:UIControlEventTouchUpInside];
        [self addSubview:oneBtn];
        oneBtn.titleLabel.font = [UIFont systemFontOfSize:14.0];
        self.oneBtn = oneBtn;
        [self.oneBtn setTitle:@"订阅" forState:UIControlStateNormal];

        
//        添加第二个按钮
        UIButton *scendBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        [scendBtn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
        [scendBtn setTitleColor:[UIColor redColor] forState:UIControlStateSelected];
        
        scendBtn.tag = 20;
        [scendBtn addTarget:self action:@selector(btnDidClick:) forControlEvents:UIControlEventTouchUpInside];
        [self addSubview:scendBtn];
         scendBtn.titleLabel.font = [UIFont systemFontOfSize:14.0];
        self.scendBtn = scendBtn;
        [self.scendBtn setTitle:@"关注" forState:UIControlStateNormal];
     
//        添加底部条
        UIView *lineView = [[UIView alloc] init];
        lineView.backgroundColor = [UIColor redColor];
        [self addSubview:lineView];
        self.lineView = lineView;
        self.seleBtn = self.oneBtn;
        self.seleBtn.selected = YES;
    }
    return self;
}

- (void)setFirstBtn:(UIButton *)firstBtn
{
    
}

//给子控件设置frame
- (void)layoutSubviews
{
    [super layoutSubviews];
    CGFloat ViewW = self.width;
    CGFloat viewH = self.height;
    self.oneBtn.frame = CGRectMake(0, 0, ViewW * 0.5, viewH);
    self.scendBtn.frame = CGRectMake(ViewW * 0.5, 0, ViewW * 0.5, viewH);
    self.lineView.frame = CGRectMake(10, viewH, ViewW * 0.5 - 20, 2);
}
#pragma mark - 按钮的点击方法实现
- (void)btnDidClick:(UIButton *)sender
{
    self.seleBtn.selected = NO;
    self.lineView.x = sender.x + 10;
    sender.selected = YES;
    self.seleBtn = sender;
    if (self.btnBlcok)
    {
        self.btnBlcok();
    }
}



@end
